﻿@model IEnumerable<rateITcd.Models.DishReview>
@using Microsoft.AspNet.Identity;
<!-- Details page: all reviews of a certain dish-->
<h1 data-i18n="[prepend]ReviewsFor"> @ViewBag.Title<span class="pull-right">

        @if (User.IsInRole("Admin") || User.IsInRole("User"))
        {
            @Html.ActionLink("Create New", "Create", "DishReview", new { id = @ViewBag.Id }, new { @class = "btn btn-default btn-sm" })
        }

    </span>
</h1>
<br />
@if (User.IsInRole("Admin") || User.IsInRole("User"))
{
    <p>
        @Html.ActionLink("Create New", "Create", "DishReview", new { id = @ViewBag.Id }, "" )
    </p>
}

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Reviewer)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Score)
        </th>
        <th data-i18n="Comment">
            @Html.DisplayNameFor(model => model.Comment)
        </th>
        @if (User.IsInRole("Admin") || User.IsInRole("User"))
        {
            <th></th>
        }

    </tr>

    @foreach (var item in @ViewBag.Reviews)
    {
        <tr>
            <td>  
                @item.Reviewer
            </td>
            <td>
                @item.Score
            </td>
            <td>
                @item.Comment
            </td>
            @if (User.IsInRole("Admin") || (User.IsInRole("User") && @item.Reviewer == User.Identity.GetUserName()))
            {
                <td>
                    @Html.ActionLink("Edit", "Edit", "DishReview", new { id = item.Id }, "") |
                    @Html.ActionLink("Delete", "Delete", "DishReview", new { id = item.Id }, "")
                </td>
            }
            else
            {
                <td></td>
            }
        </tr>
    }

</table>
